@extends('layouts.app')

@section('content')
<script type="text/javascript" charset="UTF-8" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">

    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: 'wx10cff6a634a19e12', // 必填，公众号的唯一标识
        timestamp: '{!! $config['timestamp'] !!}', // 必填，生成签名的时间戳
        nonceStr: '{!! $config['nonceStr'] !!}', // 必填，生成签名的随机串
        signature: '{!! $config['paySign'] !!}',// 必填，签名，见附录1
        jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });

    
    function callpay()
    {

        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            //jsApiCall();

            wx.chooseWXPay({
                timestamp: '{!! $config['timestamp'] !!}',
                nonceStr: '{!! $config['nonceStr'] !!}',
                package: '{!! $config['package'] !!}',
                signType: '{!! $config['signType'] !!}',
                paySign: '{!! $config['paySign'] !!}', // 支付签名
                success: function (res) {
                    // 支付成功后的回调函数
                    window.location.href="{{ url('/userinfo') }}";
                }
            });

        }
    }
    </script>

<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">确认充值</div>
                <div class="panel-body">
                    <!-- <form class="form-horizontal" role="form" method="POST" action="{{ url('/weixinpay') }}"> -->
                        {!! csrf_field() !!}

                        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">充值金额</label>

                            <div class="col-md-6">
                                
                                {{ $order->total_fee/100 }}
                                
                                
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('balance') ? ' has-error' : '' }}">
                            <label class="col-md-4 control-label">订单号</label>

                            <div class="col-md-6">
                                {{ $order->out_trade_no }}
                            </div>
                        </div>
						

                        <div class="form-group">
							<div class="col-md-6 col-md-offset-4">
                                <button type="submit" onclick="callpay()" class="btn btn-primary btn-lg btn-block">
                                    <!-- <i class="fa glyphicon glyphicon-send public-marginright10"></i> -->确认充值
                                </button>
                            </div>                            
                        </div>
                    <!-- </form> -->
                </div>
            </div>
        </div>
    </div>
</div>


@endsection
